package ui;

import static org.lwjgl.opengl.GL11.GL_POINTS;
import static org.lwjgl.opengl.GL11.GL_COMPILE;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glColor3f;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glVertex2f;
import static org.lwjgl.opengl.GL11.glGenLists;
import static org.lwjgl.opengl.GL11.glNewList;
import static org.lwjgl.opengl.GL11.glEndList;
import static org.lwjgl.opengl.GL11.glCallList;
import color.CLRConvert;
import util.Camera;

/*
 * Like the color scale but allows for two variables. HSV color is represented in this class.
 */


public class ColorSquare
{
	protected static final int pxSlideLength = UIConst.APP_WIDTH/8;
	
	protected static final float offset_x = 25.0f;
	protected static final float offset_y = UIConst.OPTIONS_PANEL_OFFSET + 25.0f;

	private int listHandle = -1;

	public ColorSquare() { }
	
	public void regenerate()
	{
		if (listHandle == -1) listHandle = glGenLists(1);
		
		double slice_hue = (360.0) / (pxSlideLength*1.0); // figure out the size of the increment for each pixel slice of the scale
		double slice_value = (90.0) / (pxSlideLength*1.0); // figure out the size of the increment for each pixel slice of the scale
		
		glNewList(listHandle, GL_COMPILE);
	        glBegin(GL_POINTS);
			for (int x = 0; x < pxSlideLength; x++)
			{
				for (int y = 0; y < pxSlideLength; y++)
				{
					float[] rgb = CLRConvert.GetStrikeDipColor(slice_hue*x, slice_value*y);
					glColor3f(rgb[0], rgb[1], rgb[2]);
					glVertex2f((float)(x + offset_x), (float)(y + offset_y));				
				}
			}
	        glEnd();
        glEndList();
	}
	
	public void render()
	{
		Camera.setOrthoON();
		glCallList(listHandle);
		Camera.setOrthoOFF();
	}
}
